<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j">

<ui:composition template="../templates/hub.xhtml">
	<ui:define name="titre">#{lbl['user.title']}</ui:define>
	<ui:define name="hub_page">

		<!-- Inclusion du bloc de navigation simple. -->
		<ui:include src="../blocs/inc_navigation_empty.xhtml" />

		<!-- La liste des utilisateurs. -->
		<h:form id="users_form">
			<h:panelGrid id="users_panel_container" width="100%">
				<!-- Le panneau des messages (pour info uniquement). -->
				<rich:messages rendered="#{userManaged.displayMessage}" />

				<rich:dataTable value="#{userManaged.lstUsers}" var="user"
					style="width:100%"
					rowClasses="rich_datagrid_even_line, rich_datagrid_odd_line"
					iterationStatusVar="it" id="users_table" styleClass="stable"
					rows="10">

					<f:facet name="noData">
						<h:outputText value="#{msg['msg.info.nodata']}" />
					</f:facet>

					<rich:column style="width:4%; text-align:center">
						<f:facet name="header">
							<h:outputText value="#{lbl['user.id']}" />
						</f:facet>
						<h:outputText value="#{user.id}" />
					</rich:column>

					<rich:column style="width:8%; text-align:center">
						<f:facet name="header">
							<h:outputText value="#{lbl['user.creation.date']}" />
						</f:facet>
						<h:outputText value="#{user.creationDate}">
							<f:convertDateTime pattern="dd/MM/yyyy" timeZone="Europe/Paris" />
						</h:outputText>
					</rich:column>

					<rich:column style="width:10%">
						<f:facet name="header">
							<h:outputText value="#{lbl['user.lastname']}" />
						</f:facet>
						<h:outputText value="#{user.lastName}" />
					</rich:column>

					<rich:column style="width:10%">
						<f:facet name="header">
							<h:outputText value="#{lbl['user.firstname']}" />
						</f:facet>
						<h:outputText value="#{user.firstName}" />
					</rich:column>

					<rich:column style="width:10%">
						<f:facet name="header">
							<h:outputText value="#{lbl['user.login']}" />
						</f:facet>
						<h:outputText value="#{user.login}" />
					</rich:column>

					<rich:column style="width:10%; text-align:center">
						<f:facet name="header">
							<h:outputText value="#{lbl['user.role']}" />
						</f:facet>
						<h:outputText value="#{user.role.label}" />
					</rich:column>

					<rich:column>
						<f:facet name="header">
							<h:outputText value="#{lbl['common.comment']}" />
						</f:facet>
						<h:outputText value="#{user.comment}" />
					</rich:column>

					<rich:column style="width:4%; text-align:center">
						<f:facet name="header">
							<h:outputText value="#{lbl['common.update']}" />
						</f:facet>
						<a4j:commandLink execute="@this" render="edit_panel"
							oncomplete="#{rich:component('edit_popup')}.show()">
							<h:graphicImage value="../../imgs/icons/ico_update.png"
								width="20" />
							<a4j:param value="#{it.index}"
								assignTo="#{userManaged.currentUserIndex}" />
							<a4j:param value="update" assignTo="#{userManaged.typeAction}" />
							<f:setPropertyActionListener target="#{userManaged.currentUser}"
								value="#{user}" />
						</a4j:commandLink>
					</rich:column>

					<rich:column style="width:4%; text-align:center">
						<f:facet name="header">
							<h:outputText value="#{lbl['common.delete']}" />
						</f:facet>
						<!-- Possibilité de supprimer l'utilisateur. -->
						<a4j:commandLink execute="@this" render="del_panel"
							rendered="#{!user.indelible}"
							oncomplete="#{rich:component('confirm_del_popup')}.show()">
							<h:graphicImage value="../../imgs/icons/ico_delete.png"
								width="20" />
							<a4j:param value="#{it.index}"
								assignTo="#{userManaged.currentUserIndex}" />
							<a4j:param value="del" assignTo="#{userManaged.typeAction}" />
							<f:setPropertyActionListener target="#{userManaged.currentUser}"
								value="#{user}" />
						</a4j:commandLink>

						<!-- Impossible de supprimer l'utilisateur Chef d'agence. -->
						<h:graphicImage value="../../imgs/icons/ico_delete_disabled.png"
							width="20" rendered="#{user.indelible}" />
					</rich:column>

					<f:facet name="footer">
						<rich:dataScroller page="#{userManaged.page}" />
					</f:facet>
				</rich:dataTable>
			</h:panelGrid>

			<!-- Pilotage des lignes tableau. -->
			<ui:include src="../blocs/inc_selector.xhtml" />

			<!-- Ajout utilisateur. -->
			<div id="create_user_div" align="right">
				<h:panelGrid columns="2">
					<h:outputText value="#{lbl['user.create']}" />
					<a4j:commandLink execute="@this" render="edit_panel"
						oncomplete="#{rich:component('edit_popup')}.show();">
						<h:graphicImage value="../../imgs/icons/ico_create.png" />
						<a4j:param value="create" assignTo="#{userManaged.typeAction}" />
					</a4j:commandLink>
				</h:panelGrid>
			</div>

			<!-- Popup pour la suppression utilisateur. -->
			<rich:popupPanel id="confirm_del_popup"
				headerClass="rich_panel_popup_head" header="#{lbl['user.confirm']}"
				autosized="true">

				<h:panelGrid styleClass="panel" width="300" height="100"
					id="del_panel">
					<h:panelGroup>
						<h:outputText value="#{msg['msg.confirm.user.delete']}" /> : 
						<h:outputText value="#{userManaged.currentUser.firstName}" /> &nbsp;
						<h:outputText value="#{userManaged.currentUser.lastName}" /> ?
					</h:panelGroup>
					<h:panelGrid columns="2" columnClasses="_left, _right" width="100%"
						style="margin-top:20px">
						<a4j:commandButton id="user_b_cancel_delete"
							value="#{lbl['common.button.cancel']}"
							onclick="#{rich:component('confirm_del_popup')}.hide(); return false;" />

						<a4j:commandButton id="user_b_delete"
							action="#{userManaged.delete}" render="users_panel_container"
							execute="@this" value="#{lbl['common.button.delete']}"
							oncomplete="if ('#{userManaged.maximumSeverity}'=='INFO'){#{rich:component('confirm_del_popup')}.hide();}" />
					</h:panelGrid>
				</h:panelGrid>
			</rich:popupPanel>

			<!-- Popup pour l'edition utilisateur. -->
			<rich:popupPanel header="#{lbl['user.edit']}" id="edit_popup"
				domElementAttachment="parent" autosized="true"
				headerClass="rich_panel_popup_head"
				onbeforeshow="centerPopup(480,300,'users_form:edit_popup');"
				onshow="makeFocusOnField('users_form:lastName');">

				<rich:messages ajaxRendered="true" layout="list" />

				<h:panelGrid columns="2" id="edit_panel"
					columnClasses="_left_top, _left" width="480">
					<h:panelGroup>
						<h:outputText value="#{lbl['user.lastname']}" /> : 
						</h:panelGroup>

					<h:inputText id="lastName" tabindex="1"
						value="#{userManaged.currentUser.lastName}" maxlength="25"
						size="30" required="true"
						requiredMessage="#{err['lastname.required']}">
						<f:validator validatorId="stringValidator" />
						<f:attribute name="fieldName" value="#{lbl['user.lastname']}" />
					</h:inputText>

					<h:panelGroup>
						<h:outputText value="#{lbl['user.firstname']}" /> : 
						</h:panelGroup>

					<h:inputText id="firstName" tabindex="2"
						value="#{userManaged.currentUser.firstName}" maxlength="25"
						size="30" required="true"
						requiredMessage="#{err['firstname.required']}">
						<f:validator validatorId="stringValidator" />
						<f:attribute name="fieldName" value="#{lbl['user.firstname']}" />
					</h:inputText>

					<h:panelGroup>
						<h:outputText value="#{lbl['user.login']}" /> : 
						</h:panelGroup>

					<h:inputText id="login" value="#{userManaged.currentUser.login}"
						maxlength="15" size="30" required="true" tabindex="3"
						validator="#{userManaged.loginUniqueValidator}"
						requiredMessage="#{err['login.required']}" />

					<h:panelGroup>
						<h:outputText value="#{lbl['user.password']}" /> : 
						</h:panelGroup>

					<h:inputSecret id="password"
						value="#{userManaged.currentUser.password}" maxlength="15"
						size="30" redisplay="true" required="true" tabindex="4"
						validator="#{userManaged.passwordUniqueValidator}"
						requiredMessage="#{err['password.required']}">
						<f:validator validatorId="passwordConfirmValidator" />
						<f:validator validatorId="lengthValidator" />
						<f:attribute name="compareTo" value="users_form:passwordConfirm" />
						<f:attribute name="minLength" value="5" />
						<f:attribute name="fieldName" value="#{lbl['user.password']}" />
					</h:inputSecret>

					<h:panelGroup>
						<h:outputText value="#{lbl['user.password.confirm']}" /> : 
						</h:panelGroup>

					<h:inputSecret id="passwordConfirm"
						value="#{userManaged.currentUser.passwordConfirm}" maxlength="15"
						size="30" redisplay="true" required="true" tabindex="5"
						requiredMessage="#{err['password.confirm.required']}" />

					<h:panelGroup>
						<h:outputText value="#{lbl['user.role']}" /> : 
						</h:panelGroup>

					<h:selectOneMenu id="role"
						value="#{userManaged.currentUser.role.id}" required="true"
						requiredMessage="#{err['role.required']}" tabindex="5">
						<f:selectItem itemLabel="#{lbl['select.role.default']}"
							itemValue="" />
						<f:selectItems value="#{repositoryManaged.lstRoles}" />
					</h:selectOneMenu>

					<h:panelGroup>
						<h:outputText value="#{lbl['common.comment']}" /> : 
						</h:panelGroup>

					<h:inputTextarea id="comment" tabindex="6"
						value="#{userManaged.currentUser.comment}" cols="60" rows="10" />
				</h:panelGrid>

				<h:panelGrid columns="2" columnClasses="_left, _right" width="100%">
					<a4j:commandButton value="#{lbl['common.button.cancel']}"
						id="user_b_cancel_edit" tabindex="7"
						onclick="#{rich:component('edit_popup')}.hide(); return false;" />

					<a4j:commandButton value="#{lbl['common.button.validate']}"
						render="users_panel_container" execute="edit_panel"
						id="user_b_edit" action="#{userManaged.edit}" tabindex="8"
						oncomplete="if ('#{userManaged.maximumSeverity}'=='INFO'){#{rich:component('edit_popup')}.hide();}" />
				</h:panelGrid>
			</rich:popupPanel>
		</h:form>
	</ui:define>
</ui:composition>
</html>